/*
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-06-09 09:49:40
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-06-26 10:45:28
 * @FilePath: \linePatrol\vue-element-plus-admin\src\store\modules\plangroup.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia'
import { store } from '../index'
import GisInfoApi from '@/api/gis/gisMap'
import {
  PnLedgerType,
  PipeLineInfoType,
  PipePointInfoType,
  PipeLineDetailType
} from '@/api/gis/type'
import { EmergencyEventType } from '@/api/Emergency/type'
import EmergencyApi from '@/api/Emergency'
import PipnentInfoApi from '@/api/equip/pipnet'

export const useGISStore = defineStore('gis', {
  state: () => {
    return {
      PipeLineInfo: [] as unknown as PipeLineInfoType[],
      PipePointInfo: [] as unknown as PipePointInfoType[],
      PipeLineDetail: {} as unknown as PipeLineDetailType,
      PnLedgerList: [] as unknown as PnLedgerType[], //管网列表
      HideDangerList: [] as unknown as EmergencyEventType[]
    }
  },
  getters: {
    getPipeLineInfo(): PipeLineInfoType[] {
      return this.PipeLineInfo
    },
    getPipePointInfo(): PipePointInfoType[] {
      return this.PipePointInfo
    },
    getPipeLineDetail(): PipeLineDetailType {
      return this.PipeLineDetail
    },
    getPnLedgerList(): PnLedgerType[] {
      return this.PnLedgerList
    },
    getHideDangerList(): EmergencyEventType[] {
      return this.HideDangerList
    },
    //根据name返回g管线名称  模糊查询
    getPipeLineByName:
      (state) =>
      (name: string): any[] => {
        if (name == '') return []
        else return state.PipeLineInfo.filter((item) => item.pipeLineName?.includes(name))
      },
    //根据name返回设施点名称  模糊查询
    getPipePointByName:
      (state) =>
      (name: string): any[] => {
        if (name == '') return []
        else return state.PipePointInfo.filter((item) => item.facName?.includes(name))
      }
  },
  actions: {
    async setPipeLineInfo() {
      this.PipeLineInfo = await GisInfoApi.GetPipeLineInfo()
      console.log(this.PipeLineInfo)
    },
    async setPipePointInfo() {
      this.PipePointInfo = await GisInfoApi.GetPipePointInfo()
      console.log(this.PipePointInfo)
    },
    async setPipeLineDetail(uuid: string | undefined) {
      this.PipeLineDetail = await GisInfoApi.GetPipeLineDetail(uuid)
    },
    async setPnLedgerList() {
      this.PnLedgerList = await PipnentInfoApi.GetpnLedgerListAll()
    },
    async setHideDangerList(params) {
      this.HideDangerList = (await EmergencyApi.GetEmergencyInfo(params)).rows
    }
  },
  persist: true
})

export const useLockStoreWithOut = () => {
  return useGISStore(store)
}
